package ee.metadataUtils.impl;

import java.util.HashMap;

import ee.metadataUtils.PropertyMetadataAdapterFactory;
import ee.metadataUtils.PropertyMetadataAdapterFactoryRegistry;

public class PropertyMetadataAdapterFactoryRegistryImpl implements
		PropertyMetadataAdapterFactoryRegistry {

	
	private HashMap<Class<?>, PropertyMetadataAdapterFactory<?>> _registeredAdapterFactories;

	public PropertyMetadataAdapterFactoryRegistryImpl()
	{
		_registeredAdapterFactories = new HashMap<Class<?>, PropertyMetadataAdapterFactory<?>>();
	}
	
	@Override
	public <T> void registerAdapterFactory(PropertyMetadataAdapterFactory<T> adapterFactory,
			Class<T> adapterType) {
		_registeredAdapterFactories.put(adapterType, adapterFactory);
	}

	@Override
	public boolean hasAdapterFactory(Class<?> adapterType) {
		return _registeredAdapterFactories.containsKey(adapterType);
	}

	@Override
	public <T> PropertyMetadataAdapterFactory<T> getAdapterFactory(Class<T> adapterType) {
		
		@SuppressWarnings("unchecked")
		PropertyMetadataAdapterFactory<T> result = (PropertyMetadataAdapterFactory<T>) _registeredAdapterFactories.get(adapterType);
		return result;
	}

}
